package com.yuanzong.wuliu.common.utils.id;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.yuanzong.wuliu.common.utils.UtilsSupport;

/**
 * 雪花算法
 */
public class SnowFlakeUtils {

    // 雪花算法
    private static Snowflake snowflake;

    public SnowFlakeUtils(UtilsSupport utilsSupport) {
        init(utilsSupport);
    }

    private void init(UtilsSupport utilsSupport) {
        snowflake = IdUtil.createSnowflake(utilsSupport.getSf_machineId(), utilsSupport.getSf_dataCenterId());
    }

    /**
     * 获取雪花算法唯一ID
     */
    public static synchronized long getId() {
        return snowflake.nextId();
    }

    public static void main(String[] args) {
        Long id = SnowFlakeUtils.getId();
        System.out.println(id);
        System.out.println((id + "").length());
    }

}
